﻿function get_service_list() {
    ajax('/goods/GetServiceList', {}, function (_0xf030x2) {
        var _0xf030x3 = 0;
        var _0xf030x4 = '';
        $['each'](_0xf030x2, function (_0xf030x5, _0xf030x6) {
            _0xf030x4 += '<label><input type="checkbox" name=service_' + _0xf030x3 + '  onclick=\'CheckService(this)\' id=service_' + _0xf030x3 + '  value=' + _0xf030x6['id'] + ' class="i- checks">' + _0xf030x6['title'] + '</label> &nbsp;&nbsp;';
            _0xf030x3++
        });
        var _0xf030x7 = '<label><input type=\'hidden\' id=\'checkboxservice\' name=\'checkboxservice\' value=' + _0xf030x3 + ' </label>';
        $('#services')['html'](_0xf030x7 + _0xf030x4)
    })
}
function CheckService(_0xf030x9) {
    var _0xf030xa = $(_0xf030x9);
    var _0xf030xb = _0xf030xa['val']();
    var _0xf030xc = addService['indexOf'](_0xf030xb);
    if (_0xf030xa['is'](':checked')) {
        if (_0xf030xc < 0) {
            addService['push'](_0xf030xb)
        }
    } else {
        if (_0xf030xc > -1) {
            addService['splice'](_0xf030xc, 1)
        }
    };
    $('#goods_service')['val'](addService)
}
function btnAddGoods() {
    var _0xf030xe = [];
    var _0xf030xf = [];
    $('#filelist0 .imgWrap img')['each'](function (_0xf030x10) {
        var _0xf030x11 = $(this)['attr']('src');
        var _0xf030x12 = _0xf030x11['indexOf']('data:');
        if (_0xf030x12 == -1) {
            var _0xf030x13 = _0xf030x11['indexOf']('/upload');
            var _0xf030x14 = _0xf030x11['substring'](_0xf030x13);
            _0xf030xe['push'](_0xf030x14)
        }
    });
    $('#filelist1 .imgWrap img')['each'](function (_0xf030x10) {
        var _0xf030x11 = $(this)['attr']('src');
        var _0xf030x12 = _0xf030x11['indexOf']('data:');
        if (_0xf030x12 == -1) {
            var _0xf030x13 = _0xf030x11['indexOf']('/upload');
            var _0xf030x14 = _0xf030x11['substring'](_0xf030x13);
            _0xf030xf['push'](_0xf030x14)
        }
    });
    var _0xf030x15 = $['trim']($('#sale_price')['val']());
    var _0xf030x16 = $['trim']($('#market_price')['val']());
    var _0xf030x17 = $['trim']($('#settlement_price')['val']());
    if (_0xf030x15 == '') {
        layer['msg']('请输入平台价', {
            icon: 5,
            time: 2000
        });
        return false
    };
    if (_0xf030x16 == '') {
        layer['msg']('请输入市场价', {
            icon: 5,
            time: 2000
        });
        return false
    };
    var _0xf030x18 = $('#type_id')['val']();
    if (_0xf030x18 != 1 && _0xf030x17 == '') {
        layer['msg']('请输入结算价', {
            icon: 5,
            time: 2000
        });
        return false
    };
    var _0xf030x19 = $('#freight_chargetype')['val']();
    var _0xf030x1a = $('#weight')['val']();
    if (_0xf030x19 != undefined && _0xf030x19 == '3' && _0xf030x1a == '') {
        layer['msg']('该运费模板按重量计算运费，请输入商品重量', {
            icon: 5,
            time: 2000
        });
        return false
    };
    if (_0xf030xe['length'] == 0) {
        layer['msg']('请至少上传一张商品图片', {
            time: 2000
        });
        return false
    };
    var _0xf030x18 = $('#type_id')['val']();
    var _0xf030x1b = $['trim']($('#service_rate')['val']());
    if (_0xf030x18 == 1 && _0xf030x1b != undefined && _0xf030x1b == '') {
        layer['msg']('请输入服务费率', {
            icon: 5,
            time: 2000
        });
        return false
    };
    $('#btnSave')['hide']();
    var _0xf030x1c = _0xf030xe[0];
    var _0xf030x1d = $('#form-add')['serializeArray']();
    var _0xf030x1e = {};
    $['each'](_0xf030x1d, function (_0xf030x10, _0xf030x1f) {
        _0xf030x1e[_0xf030x1f['name']] = _0xf030x1f['value']
    });
    _0xf030x1e['banner_img_List'] = _0xf030xe;
    _0xf030x1e['info_img_List'] = _0xf030xf;
    $['ajax']({
        type: 'post',
        url: '/goods/AddorEditGoodsInfo',
        dataType: 'json',
        data: _0xf030x1e,
        success: function (_0xf030x2) {
            if (_0xf030x2['status'] == 'y') {
                layer['msg']('保存成功', {
                    icon: 6,
                    time: 1200
                }, function () {
                    $['ajax']({
                        type: 'POST',
                        url: domain + '/Tools/CreateMulThumImg',
                        data: {
                            path: _0xf030x1c
                        },
                        dataType: 'json',
                        success: function (_0xf030x20) {
                            window['location']['href'] = '/goods/GoodsSpec/' + _0xf030x2['info']
                        }
                    })
                })
            } else {
                layer['msg'](_0xf030x2['info'], {
                    icon: 5,
                    time: 2000
                }, function () {
                    $('#btnSave')['show']()
                })
            }
        }
    })
}
function setGoodsService() {
    if (goods_service != undefined && goods_service != '') {
        addService = goods_service['split'](',');
        ajax('/goods/GetServiceList', {}, function (_0xf030x2) {
            var _0xf030x3 = 0;
            var _0xf030x4 = '';
            $['each'](_0xf030x2, function (_0xf030x5, _0xf030x6) {
                if (addService['indexOf'](_0xf030x6['id'].toString()) == -1) {
                    _0xf030x4 += '<label><input type="checkbox" name=service_' + _0xf030x3 + '  onclick=\'CheckService(this)\' id=service_' + _0xf030x3 + '  value=' + _0xf030x6['id'] + ' class="i- checks">' + _0xf030x6['title'] + '</label> &nbsp;&nbsp;'
                } else {
                    _0xf030x4 += '<label><input type="checkbox" name=service_' + _0xf030x3 + ' checked=\'checked\'   onclick=\'CheckService(this)\' id=service_' + _0xf030x3 + '  value=' + _0xf030x6['id'] + ' class="i- checks">' + _0xf030x6['title'] + '</label> &nbsp;&nbsp;'
                };
                _0xf030x3++
            });
            var _0xf030x7 = '<label><input type=\'hidden\' id=\'checkboxservice\' name=\'checkboxservice\' value=' + _0xf030x3 + ' </label>';
            $('#services')['html'](_0xf030x7 + _0xf030x4)
        })
    } else {
        get_service_list()
    }
}
function GetImgList0(_0xf030x23) {
    ajax('/goods/GetGoodsPictures/' + _0xf030x23 + '/0', {}, function (_0xf030x2) {
        var _0xf030x24 = $('#filelist0');
        var _0xf030x25 = '';
        if (_0xf030x2 != null && _0xf030x2['length'] > 0) {
            for (var _0xf030x10 = 0; _0xf030x10 < _0xf030x2['length']; _0xf030x10++) {
                _0xf030x25 = _0xf030x25 + ('<li id="BWU_FILE_' + _0xf030x10 + '" draggable="true" class="state-complete" style="display: block;"><div class="item">' + '<p class="title">&nbsp;</p>' + '<p class="imgWrap"><img src="' + domain + _0xf030x2[_0xf030x10]['url'] + '"></p>' + '<p class="progress"><span style="display: none; width: 0px;"></span></p>' + '<div class="file-panel" style="height: 30px;"><span class="cancel" onclick="delImg(\'BWU_FILE_' + _0xf030x10 + '\',' + _0xf030x10 + ')">\u5220\u9664</span></div>' + '</div><span class="success"></span></li>');
                if (_0xf030x10 == 0) {
                    default_pic = _0xf030x2[_0xf030x10]['url']
                }
            };
            _0xf030x24['html'](_0xf030x25);
            _0xf030x24['sortable']()
        }
    })
}
function GetImgList1(_0xf030x23) {
    ajax('/goods/GetGoodsPictures/' + _0xf030x23 + '/1', {}, function (_0xf030x2) {
        var _0xf030x24 = $('#filelist1');
        var _0xf030x25 = '';
        if (_0xf030x2 != null && _0xf030x2['length'] > 0) {
            for (var _0xf030x10 = 0; _0xf030x10 < _0xf030x2['length']; _0xf030x10++) {
                _0xf030x25 = _0xf030x25 + ('<li id="CWU_FILE_' + _0xf030x10 + '" draggable="true" class="state-complete" style="display: block;"><div class="item">' + '<p class="title">&nbsp;</p>' + '<p class="imgWrap"><img src="' + domain + _0xf030x2[_0xf030x10]['url'] + '"></p>' + '<p class="progress"><span style="display: none; width: 0px;"></span></p>' + '<div class="file-panel" style="height: 30px;"><span class="cancel" onclick="delImg(\'CWU_FILE_' + _0xf030x10 + '\',' + _0xf030x10 + ')">\u5220\u9664</span></div>' + '</div><span class="success"></span></li>')
            };
            _0xf030x24['html'](_0xf030x25);
            _0xf030x24['sortable']()
        }
    })
}
function delImg(_0xf030x9, _0xf030x28) {
    $('#' + _0xf030x9)['remove']()
}
function btnEditGoods() {
    var _0xf030xe = [];
    var _0xf030xf = [];
    $('#filelist0 .imgWrap img')['each'](function (_0xf030x10) {
        var _0xf030x11 = $(this)['attr']('src');
        var _0xf030x12 = _0xf030x11['indexOf']('data:');
        if (_0xf030x12 == -1) {
            var _0xf030x13 = _0xf030x11['indexOf']('/upload');
            var _0xf030x14 = _0xf030x11['substring'](_0xf030x13);
            _0xf030xe['push'](_0xf030x14)
        }
    });
    $('#filelist1 .imgWrap img')['each'](function (_0xf030x10) {
        var _0xf030x11 = $(this)['attr']('src');
        var _0xf030x12 = _0xf030x11['indexOf']('data:');
        if (_0xf030x12 == -1) {
            var _0xf030x13 = _0xf030x11['indexOf']('/upload');
            var _0xf030x14 = _0xf030x11['substring'](_0xf030x13);
            _0xf030xf['push'](_0xf030x14)
        }
    });
    var _0xf030x2a = $('#gc_id2')['val']();
    if (_0xf030x2a != undefined && _0xf030x2a['length'] == 0) {
        layer['msg']('请选择商品类别', {
            time: 2000
        });
        return false
    };
    var _0xf030x15 = $['trim']($('#sale_price')['val']());
    var _0xf030x16 = $['trim']($('#market_price')['val']());
    var _0xf030x17 = $['trim']($('#settlement_price')['val']());
    if (_0xf030x15 == '') {
        layer['msg']('请输入平台价', {
            icon: 5,
            time: 2000
        });
        return false
    };
    if (_0xf030x16 == '') {
        layer['msg']('请输入市场价', {
            icon: 5,
            time: 2000
        });
        return false
    };
    var _0xf030x18 = $('#type_id')['val']();
    if (_0xf030x18 != 1 && _0xf030x17 == '') {
        layer['msg']('请输入结算价', {
            icon: 5,
            time: 2000
        });
        return false
    };
    var _0xf030x19 = $('#freight_chargetype')['val']();
    var _0xf030x1a = $('#weight')['val']();
    if (_0xf030x19 != undefined && _0xf030x19 == '3' && _0xf030x1a == '') {
        layer['msg']('该运费模板按重量计算运费，请输入商品重量', {
            icon: 5,
            time: 2000
        });
        return false
    };
    if (_0xf030xe['length'] == 0) {
        layer['msg']('请至少上传一张商品图片', {
            icon: 5,
            time: 2000
        });
        return false
    };
    var _0xf030x18 = $('#type_id')['val']();
    var _0xf030x1b = $['trim']($('#service_rate')['val']());
    if (_0xf030x18 == 1 && _0xf030x1b != undefined && _0xf030x1b == '') {
        layer['msg']('请输入服务费率', {
            icon: 5,
            time: 2000
        });
        return false
    };
    $('#btnSave')['hide']();
    var _0xf030x1c = _0xf030xe[0];
    var _0xf030x1d = $('#form-add')['serializeArray']();
    var _0xf030x1e = {};
    $['each'](_0xf030x1d, function (_0xf030x10, _0xf030x1f) {
        _0xf030x1e[_0xf030x1f['name']] = _0xf030x1f['value']
    });
    _0xf030x1e['banner_img_List'] = _0xf030xe;
    _0xf030x1e['info_img_List'] = _0xf030xf;
    $['ajax']({
        type: 'post',
        url: '/goods/AddorEditGoodsInfo',
        dataType: 'json',
        data: _0xf030x1e,
        success: function (_0xf030x2) {
            if (_0xf030x2['status'] == 'y') {
                var _0xf030x2b = '操作成功';
                if (_0xf030x2['type'] == '1') {
                    _0xf030x2b = '操作成功，价格变动，请及时修改SKU价格！'
                };
                layer['msg'](_0xf030x2b, {
                    icon: 6,
                    time: 2000
                }, function () {
                    if (default_pic == _0xf030x1c) {
                        for (var _0xf030x10 = 0; _0xf030x10 < _0xf030xe['length']; _0xf030x10++) {
                            $['ajax']({
                                type: 'POST',
                                url: domain + '/Tools/Create750_750Img',
                                data: {
                                    path: _0xf030xe[_0xf030x10]
                                },
                                dataType: 'json',
                                success: function (_0xf030x2) {
                                    console['log'](_0xf030x2)
                                }
                            })
                        };
                        $('#btnSave')['show']()
                    } else {
                        $['ajax']({
                            type: 'POST',
                            url: domain + '/Tools/CreateMulThumImg',
                            data: {
                                path: _0xf030x1c
                            },
                            dataType: 'json',
                            success: function (_0xf030x2) {
                                $('#btnSave')['show']()
                            }
                        })
                    }
                })
            } else {
                layer['msg'](_0xf030x2['info'], {
                    icon: 5,
                    time: 2000
                }, function () {
                    $('#btnSave')['show']()
                })
            }
        }
    })
}
function UpdateImgSize() {
    var _0xf030x2d = [];
    $('#filelist0 .imgWrap img')['each'](function (_0xf030x10) {
        var _0xf030x11 = $(this)['attr']('src');
        var _0xf030x13 = _0xf030x11['indexOf']('/upload');
        var _0xf030x14 = _0xf030x11['substring'](_0xf030x13);
        _0xf030x2d['push'](_0xf030x14)
    });
    if (_0xf030x2d['length'] > 0) {
        for (var _0xf030x10 = 0; _0xf030x10 < _0xf030x2d['length']; _0xf030x10++) {
            if (_0xf030x10 == 0) {
                $['ajax']({
                    type: 'POST',
                    url: domain + '/Tools/CreateMulThumImg',
                    data: {
                        path: _0xf030x2d[0]
                    },
                    dataType: 'json',
                    success: function (_0xf030x2) {
                        console['log'](_0xf030x2)
                    }
                })
            } else {
                $['ajax']({
                    type: 'POST',
                    url: domain + '/Tools/Create750_750Img',
                    data: {
                        path: _0xf030x2d[_0xf030x10]
                    },
                    dataType: 'json',
                    success: function (_0xf030x2) {
                        console['log'](_0xf030x2)
                    }
                })
            }
        }
    }
}
$('#gc_id1')['change'](function () {
    var _0xf030x2e = $(this)['val']();
    if (_0xf030x2e != '') {
        getClass(_0xf030x2e, '#gc_id2', t_id);
        $('#category_id1')['val'](_0xf030x2e)
    } else {
        $('#gc_id2')['html']('<option value=\'\'>二级分类</option>')
    }
});
$('#gc_id2')['change'](function () {
    var _0xf030x2f = $(this)['val']();
    if (_0xf030x2f != '') {
        $('#category_id2')['val'](_0xf030x2f);
        $('#category_id')['val'](_0xf030x2f)
    }
});

function getClass(_0xf030x31, _0xf030x9, _0xf030x32, _0xf030x33) {
    if (_0xf030x32 == 4) {
        _0xf030x32 = 2
    };
    ajax('/tools/GetCategoryList/' + _0xf030x31 + '/' + _0xf030x32, {}, function (_0xf030x2) {
        var _0xf030x4 = '<option value=\'\'>请选择</option>';
        $['each'](_0xf030x2, function (_0xf030x5, _0xf030x6) {
            _0xf030x4 += '<option value=\'' + _0xf030x6['id'] + '\'>' + _0xf030x6['name'] + '</option>'
        });
        $(_0xf030x9)['html'](_0xf030x4);
        $(_0xf030x9)['show']();
        if (_0xf030x33 != undefined && _0xf030x33 != '') {
            $(_0xf030x9)['val'](_0xf030x33)
        }
    })
}
function get_freight_template(_0xf030x35, _0xf030x9, _0xf030x33) {
    ajax('/tools/GetFreightTemplats/' + _0xf030x35, {}, function (_0xf030x2) {
        var _0xf030x4 = '<option typedata=\'\' value=\'-1\'>请选择模板</option>';
        $['each'](_0xf030x2, function (_0xf030x5, _0xf030x6) {
            _0xf030x4 += '<option typedata=\'' + _0xf030x6['chargetype'] + '\' value=\'' + _0xf030x6['id'] + '\'>' + _0xf030x6['name'] + '</option>'
        });
        $(_0xf030x9)['html'](_0xf030x4);
        if (_0xf030x33 != undefined && _0xf030x33 != '') {
            $(_0xf030x9)['val'](_0xf030x33)
        }
    })
}
$('#freight_template')['change'](function () {
    var _0xf030x2e = $(this)['val']();
    var _0xf030x36 = $(this)['find']('option:selected')['attr']('typedata');
    $('#freight_template_id')['val'](_0xf030x2e);
    $('#freight_chargetype')['val'](_0xf030x36)
})